<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>雇佣邀请</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/order/get_work_frm.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/my/joboffer/joboffer.css" />
    <style>

    </style>
</head>

<body>
    <div id="app" v-clock>
        <div class="tab-content" v-clock>
            <div class="list-for-item" v-for="o,i in list">
                <div class="aui-list" @click="openInfo({id:o.work_id,isMobile:o.apply_status===2})">
                    <div class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-title aui-ellipsis-1">{{o.title}}</div>
                        </div>
                    </div>
                    <div class="aui-list-item">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-media">
                                <img :src="o.headimgurl" onerror='this.src="../../../image/portrait.png"'>
                            </div>
                            <div class="person_info">
                                <div> <img src="../../../image/icon/menu02-1.png" class="iconimg" alt=""> <span>联系人：{{o.contact}}</span></div>
                                <div> <img src="../../../image/icon/daohang.png" class="iconimg" alt=""> <span>项目地点：{{o.region}}</span></div>
                                <div> <img src="../../../image/icon/time.png" class="iconimg" alt=""> <span>发布时间：{{o.work_date}}</span></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="btn-group" style="justify-content: space-between;align-items:center;">
                    <div style="font-size:0.6rem;color:#C1C1C1;"></div>
                    <div style="display:flex;align-items:center;">
                        <div v-if="o.apply_status===0" class="failure">已拒绝</div>

                        <div class="btn" v-if="o.apply_status===1" @click="accept(o,i)">接活</div>
                        <div class="btn" v-if="o.apply_status===1" @click="cancel(o,i)">拒绝</div>

                        <div v-if="o.apply_status===2" class="failure">已接活</div>
                        <div v-if="o.apply_status===2" class="btn" @click="openWin('goOrder')">去订单</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            userInfo: {},
            list: [],
            listStatus: true,
            listPage: 1
        },
        methods: {
            init() {
                this.userInfo = get_local('userInfo');
                // 上拉加载
                this.upDownLoad();
                // 雇佣列表
                this.getList();
            },
            getList() {
                var that = this;
                var data = {
                    user_id: that.userInfo.user_id,
                    pages: that.listPage
                };
                _ajax(Config.api.UserEmployUserSpecialtyInvite, data, function(ret) {
                    if (ret.code === 200) {
                        if (that.listPage === 1) {
                            that.list = ret.data;
                        } else {
                            if (ret.data.length > 0) {
                                that.list = that.list.concat(ret.data);
                            } else {
                                that.listStatus = false;
                            }
                        }
                    }
                });
            },
            openInfo(o) {
                var winInfo = {
                    name: 'demand_details_new_win',
                    url: '../../details/demand_details_new_win.html',
                };
                open_w(winInfo.name, winInfo.url, o);
            },
            accept(o, i) {
                var that = this;
                var data = {
                    apply_user_id: this.userInfo.user_id,
                    apply_id: o.apply_id,
                    work_user_id: o.work_user_id,
                    work_id: o.work_id,
                };
                _ajax(Config.api.UserEmployUserSpecialtyAccept, data, function(ret) {
                    if (ret.code === 200) {
                        that.list[i].apply_status = 2;
                        $toast("接活成功");
                    } else {
                        $toast("接活失败");
                    }
                });
            },
            cancel(o, i) {
                var that = this;
                var data = {
                    apply_user_id: this.userInfo.user_id,
                    apply_id: o.apply_id,
                    work_user_id: o.work_user_id,
                    work_id: o.work_id,
                };
                _ajax(Config.api.UserEmployUserSpecialtyCancel, data, function(ret) {
                    if (ret.code === 200) {
                        that.list[i].apply_status = 0;
                        $toast("拒绝成功");
                    } else {
                        $toast("拒绝失败");
                    }
                });
            },
            openWin(name) {
                var winInfo = {
                    // 专业用工详情
                    specialty_particulars: {
                        name: 'particulars_win',
                        url: '../../home/bus_res/specialty/particulars_win.html'
                    },
                    // 零工详情
                    odd_job_particulars: {
                        name: 'particulars_win',
                        url: '../../home/bus_res/odd_job/particulars_win.html'
                    },
                    // 去订单
                    goOrder: {
                        name: 'get_work_win',
                        url: '../../order/get_work/get_work_win.html'
                    }
                };
                if (name) {
                    open_w(winInfo[name].name, winInfo[name].url);
                } else {
                    $toast("正在开发中...");
                }
            },
            upDownLoad() {
                var that = this;

                // 下拉刷新
                push_down(function() {
                    //下拉刷新恢复
                    push_down_over();
                    that.listStatus = true;
                    that.listPage = 1;
                    that.getList();
                });

                //上拉加载
                push_up(function() {
                    if (that.listStatus) {
                        that.listPage++;
                        that.getList();
                    }
                });
            }
        }
    });
</script>

</html>
